//package org.onvivals.app.ai.tts.model.azure;
//
//import cn.hutool.core.io.FileUtil;
//import cn.hutool.core.util.IdUtil;
//import cn.hutool.json.JSONObject;
//import com.alibaba.nls.client.protocol.NlsClient;
//import lombok.extern.slf4j.Slf4j;
//import org.onvivals.app.ai.tts.AbstractTtsService;
//
//import java.io.File;
//import java.util.Optional;
//import java.util.concurrent.locks.Lock;
//import java.util.concurrent.locks.ReentrantLock;
//
///**
// * @Author: Mr.ZS
// * @Date: 2024/9/29 下午9:12
// * @company 湖南葆龄科技有限公司
// **/
//@Slf4j
//public class AzureTtsService extends AbstractTtsService {
//
//    private static final Lock lock = new ReentrantLock();
//	private static StringBuffer fileUrl = new StringBuffer();
//	private JSONObject ttsConfig;
//
//	private NlsClient client;
//
//	public AzureTtsService(JSONObject config) {
//		this.ttsConfig = config;
//	}
//
//	public static String generateFilePath() {
//		lock.lock();
//		try {
//			String tmpDir = System.getProperty("java.io.tmpdir");
//			String uniqueId = IdUtil.getSnowflakeNextIdStr();
//			return tmpDir + uniqueId + ".mp3";
//		} finally {
//			lock.unlock();
//		}
//	}
////        /**
////     * 文字转换语音
////     *
////     * @param content 转换的文字
////     * @return Optional<String> 文件路径
////     */
////    @Override
////    public Optional<String> speechSynthesizer(String id, String content) {
////        try {
////            String key = ttsConfig.getStr("key");
////            String serviceRegion = ttsConfig.getStr("service_region");
////            String voiceName = ttsConfig.getStr("voice_name");
////            String filePath = generateFilePath();
////            SpeechConfig speechConfig = SpeechConfig.fromSubscription(key, serviceRegion);//key,地区
////            speechConfig.setSpeechSynthesisLanguage("zh-CN");//语言
////            speechConfig.setSpeechSynthesisVoiceName(voiceName);//语言名称
////            speechConfig.setSpeechSynthesisOutputFormat(SpeechSynthesisOutputFormat.Audio16Khz32KBitRateMonoMp3);
////            SpeechSynthesizer synthesizer = new SpeechSynthesizer(speechConfig, null);
////            SpeechSynthesisResult result = synthesizer.SpeakText(content);
////            byte[] audioData = result.getAudioData();
////            File f = new File(filePath);
////            FileUtil.writeBytes(audioData, f);
////            return Optional.of(filePath);
////        } catch (Exception e) {
////            log.error("AzureTtsService speechSynthesizer error", e);
////        }
////        return Optional.empty();
////    }
//
//}
